const fs=require('fs');

const ws = fs.createWriteStream('./test.txt');

var tid=setInterval(()=>{
	const num=parseInt(Math.random()*10);
	console.log(num);
	if(num<7){
		ws.write(''+num)
	}else{
		clearInterval(tid)
		ws.end();
	}

},1000);

ws.on('funish',()=>{
	console.log('Done!');
});
